﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VCC.CMS.ViewModels.BoxSearchAdModel>" %>
<form method="post" action="/Ad/Index">
    <div class="home-search-box">
            <div class="tops">
                <h1>
                    Công cụ tìm kiếm</h1>
            </div>
            <div class="contents">
                <div id="divOfSeach">
                    <div class="home-product-search">
                        <div id="searchArea" style="padding-top: 5px">
                            <div class="comboboxs">
                                <%=Html.DropDownListFor(m => m.CurCountryID, new SelectList(Model.Countries, "ID", "Name",Model.CurCountryID != null ? Model.CurCountryID : 0).ToList(),"--Quốc gia--")%>
                            </div>
                            <div class="comboboxs">
                                <%=Html.DropDownListFor(m=> m.CurAreaID,new SelectList(Model.Areas,"ID","Name",Model.CurAreaID != null ? Model.CurAreaID : 0).ToList(),"--Cả nước--")%>
                            </div>
                            <div class="comboboxs">
                                <%=Html.DropDownListFor(m => m.CurCityID, new SelectList(Model.Cities, "ID", "Name", Model.CurCityID != null ? Model.CurCityID : 0).ToList(), "--Tỉnh thành--", new { style = "width: 145px;" })%>
                            </div>
                            <div class="comboboxs">
                                <%=Html.DropDownListFor(m => m.CurDistrictID, new SelectList(Model.Districts, "ID", "Name", Model.CurDistrictID != null ? Model.CurDistrictID : 0).ToList(), "--Quận/huyện--", new { style = "width:145px" })%>
                            </div>
                            <div class="comboboxs" id="divPrice">
                                <%=Html.DropDownListFor(m=> m.CurDemandID,new SelectList(Model.Demands,"ID","Name",Model.CurDemandID!= null ? Model.CurDemandID : 0).ToList(),"--Nhu cầu--") %>
                            </div>
                            <div class="comboboxs">
                                <%=Html.DropDownListFor(m=> m.CurCusTypeID,new SelectList(Model.CusTypes,"Key","Value",Model.CurCusTypeID).ToList(),"--Loại tin--")%>                    
                            </div>
                            <div class="comboboxs">
                                <%= Html.DropDownListFor(m => m.CurCategoryID, new SelectList(Model.Categories, "Value", "Text", Model.CurCategoryID).ToList(), "--Danh mục--")%>
                            </div>
                            <%=Html.TextBoxFor(m => m.Keyword, new { style = "width:180px", placeholder = "Nhập từ khóa tìm kiếm..." })%>
                        </div>
                        <div class="timkiems">
                            <input type="submit" id="btnSearch" class="actionBtn" value="Tìm kiếm" />
                        </div>
                        <div class="message">
                            Có trên<strong> 1000</strong> tin mới mỗi ngày
                        </div>
                    </div>
                </div>
            </div>
        </div>
</form>
<script type="text/javascript">
    $(document).ready(function() {
//        $("#buttonsearch").click(function() {
//            var className = $('#buttonsearch').attr('class');
//            if ((className == "") || (className == "hidden1")) {
//                $("#buttonsearch").removeClass();
//                $("#buttonsearch").addClass("active1");
//                $("#advance").css("display", "block");
//            }
//            else {
//                $("#buttonsearch").removeClass();
//                $("#buttonsearch").addClass("hidden1");
//                $("#advance").css("display", "none");
//            }

//        });

        // Change country auto change areas, city, district and category
        $("#CurCountryID").unbind("change").change(function() {
        var val = $("#CurCountryID").val();
            if (val == "" || val == '' || val == undefined)
                val = 0;
            // Change Areas
            AjaxChange("#CurCountryID", "#CurAreaID", "/Applications/LoadAreaByCountry/");
            // Change City
            AjaxChange("#CurCountryID", "#CurCityID", "/Applications/LoadCityByCountry/");
            // Change Distric
            AjaxChange("#CurCityID", "#CurDistrictID", "/Applications/LoadDistrictByCity/");
            // Change Category
            //  AjaxChange("#Country_ID", "#Category_ID", "/Applications/LoadCategoryByCountry/");
        });

        $("#CurAreaID").unbind("change").change(function() {
        var val = $("#CurAreaID").val();
            if (val == "" || val == '' || val == undefined)
                val = 0;
            AjaxChange("#CurAreaID", "#CurCityID", "/Applications/LoadCityByArea/");
            // Change Distric
            AjaxChange("#CurCityID", "#CurDistrictID", "/Applications/LoadDistrictByCity/");
        });
        $("#CurCityID").unbind("change").change(function() {
        var val = $("#CurCityID").val();
            if (val == "" || val == '' || val == undefined)
                return false;
            AjaxChange("#CurCityID", "#CurDistrictID", "/Applications/LoadDistrictByCity/");
        });

        // Autocomplete
        $("#Keyword").autocomplete({
        source: function(request, response) {
        var dm = GetDomain();
                var ul = dm + "/Applications/SearchAd";
                $.ajax({
                    url: ul,
                    dataType: "json",
                    data: {
                        keyword: request.term
                    },
                    success: function(data) {
                        response($.map(data, function(item) {
                            return {
                                label: item.Title,
                                id: item.ID
                            }
                        }));
                    }
                });
            },
            minLength: 1,
            select: function(event, ui) {
                $("#Keyword").val(ui.item.label);
                return false;
            }
        });
    });
</script>

